/**
 * 
 */
package com.gkwave.action.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gkwave.module.bean.MessageBean;
import com.gkwave.module.dao.EmailDAO;
import com.gkwave.module.dao.TransportCabRequestDAO;

/**
 * @author Administrator
 *
 */
public class TransportCabRequestService extends BaseService {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6412232822489146615L;

	/* (non-Javadoc)
	 * @see com.gkwave.action.service.BaseService#procesRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public void procesRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
    	String nmCity = request.getParameter("nmCity");
    	String nmName = request.getParameter("nmName");
    	String nmPickupPoint = request.getParameter("nmPickupPoint");
    	String nmDroppingPoint = request.getParameter("nmDroppingPoint");
    	String nmUserId = request.getParameter("nmUserId");
    	String nmSupervicerId = request.getParameter("nmSupervicerId");
    	String nrMobileNumber = request.getParameter("nrMobileNumber");
    	String tsTime = request.getParameter("tsTime");
    	String dtDate = request.getParameter("dtDate");
    	String idUser = request.getParameter("idUser");
    	out = response.getWriter();
    	TransportCabRequestDAO dao = null;
    	
    	if(nmCity!=null && nmName!=null && nmPickupPoint!=null && nmDroppingPoint!=null && 
    	   nmUserId!=null && nmSupervicerId!=null && nrMobileNumber!=null && tsTime!=null && dtDate!=null){
    		Integer id_user = Integer.parseInt(idUser);
    		dao = new TransportCabRequestDAO();
    		MessageBean message = dao.doCabRequest(nmCity, nmName, nmPickupPoint, nmDroppingPoint,nmUserId, nmSupervicerId, nrMobileNumber, tsTime, dtDate,id_user);
    		if(message.getStatus().equals("Success")){
				StringBuffer messageContent  = new StringBuffer();
				messageContent.append("Cab request Details:");
				messageContent.append("\n====================\n");
				messageContent.append("Persion name: " + nmName);
				messageContent.append("\n");
				messageContent.append("User ID : " + idUser);
				messageContent.append("\n");
				messageContent.append("City : " + nmCity);
				messageContent.append("\n");
				messageContent.append("Pick-up point: " + nmPickupPoint);
				messageContent.append("\n");
				messageContent.append("Dropping Point: " + nmDroppingPoint);
				messageContent.append("\n");
				messageContent.append("Mobile number: " + nrMobileNumber);
				messageContent.append("\n");
				messageContent.append("Date: " + dtDate);
				messageContent.append("\n");
				messageContent.append("Time: " + tsTime);
				messageContent.append("\n");
    			
    			sendEmailNotification(messageContent,nmSupervicerId);
    		}
    		xmlResponse = message.marsel(message);
    	}
    	System.out.println(xmlResponse);
    	out.println(xmlResponse);
	}

	private void sendEmailNotification(StringBuffer messageContent, String idEmail) {
		// TODO Auto-generated method stub
		EmailDAO.sendEmailNotification("[SMARTC Notification] Cab Request", messageContent.toString(), new String[]{idEmail});
	}

}
